Skip to content

test: add unit tests for IsPodReady, IsPodReadyConditionTrue and GetP…#7668

Open
tushar-pandhare wants to merge 1 commit into
karmada-io:masterfrom
tushar-pandhare:test-pod-ready-helpers
Open

test: add unit tests for IsPodReady, IsPodReadyConditionTrue and GetP…#7668
tushar-pandhare wants to merge 1 commit into
karmada-io:masterfrom
tushar-pandhare:test-pod-ready-helpers

Conversation

@tushar-pandhare

Copy link
Copy Markdown
Contributor

/kind cleanup

What this PR does / why we need it:
Add unit tests for three functions in pkg/util/helper/pod.go that lacked test coverage:

  • IsPodReady — tests no conditions, Ready=False, Ready=True
  • IsPodReadyConditionTrue — tests no conditions, Ready=False, Ready=Unknown, Ready=True
  • GetPodReadyCondition — tests no conditions, Ready condition absent, Ready condition present

Which issue(s) this PR fixes:
Fixes: #7667

Special notes for your reviewer:
All existing tests pass with the new additions:
ok github.com/karmada-io/karmada/pkg/util/helper

Does this PR introduce a user-facing change?:
NONE

…odReadyCondition

Signed-off-by: Tushar Pandhare <tusharpandharetp@gmail.com>
Copilot AI review requested due to automatic review settings June 26, 2026 15:32
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jun 26, 2026
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the test coverage for core pod utility functions within the project. By introducing unit tests for status-related helper methods, it ensures that pod condition logic behaves as expected across different edge cases, contributing to better overall system reliability.

Highlights

  • Unit Test Coverage: Added comprehensive unit tests for IsPodReady, IsPodReadyConditionTrue, and GetPodReadyCondition functions in pkg/util/helper/pod.go.
  • Test Scenarios: Implemented various test cases including scenarios with no conditions, varying condition statuses (True, False, Unknown), and missing conditions to ensure robust validation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign chaunceyjiang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds unit tests for the IsPodReady, IsPodReadyConditionTrue, and GetPodReadyCondition helper functions in pkg/util/helper/pod_test.go. The review feedback highlights a potential panic in the IsPodReady helper function due to a missing nil check on the pod parameter, and suggests updating the helper function to handle nil safely and adding a corresponding test case.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

})
}
}
func TestIsPodReady(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The helper function IsPodReady in pod.go does not perform a nil check on the pod parameter before accessing pod.Status. This can lead to a panic if a nil pod is passed. Please consider updating IsPodReady to handle nil safely (e.g., returning false), and then add a corresponding test case in TestIsPodReady to verify this behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing unit test coverage for pod readiness helper functions in pkg/util/helper/pod.go, ensuring key readiness-condition branches are explicitly validated and reducing regression risk in readiness-related logic.

Changes:

  • Add table-driven unit tests for IsPodReady covering no conditions, Ready=False, Ready=True.
  • Add table-driven unit tests for IsPodReadyConditionTrue covering no conditions, Ready=False, Ready=Unknown, Ready=True.
  • Add table-driven unit tests for GetPodReadyCondition covering no conditions, Ready condition absent, Ready condition present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.06%. Comparing base (1ae5ac6) to head (c49b093).
⚠️ Report is 27 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7668      +/-   ##
==========================================
- Coverage   42.15%   42.06%   -0.10%     
==========================================
  Files         879      879              
  Lines       54669    54827     +158     
==========================================
+ Hits        23047    23063      +16     
- Misses      29875    30018     +143     
+ Partials     1747     1746       -1     
Flag Coverage Δ
unittests 42.06% <ø> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tushar-pandhare

Copy link
Copy Markdown
Contributor Author

@RainbowMango @zhzhuang-zju PTAL, Thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit tests for IsPodReady, IsPodReadyConditionTrue and GetPodReadyCondition

4 participants